﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Models;

namespace Admin
{
    public partial class newslist : System.Web.UI.Page
    {
        private int Nowpage = 1;
        private const int PAGESIZE = 5;
        private int pagecount = NewsInfoLogic.GetPageCount(PAGESIZE);

        protected void Page_Load(object sender, EventArgs e)
        {
            try{
                Nowpage = Int32.Parse(Request.QueryString["page"].ToString());
            }catch{
                Nowpage = 1;
            }
            NewsListBindData(Nowpage);
            NewsListPageBindData(Nowpage);
        }
        private void BindData()
        {

        }
        private void NewsListBindData(int nowPage)
        {
            List<NewsInfoList> newslist = new List<NewsInfoList>();
            List<NewsInfo> newsinfo = new List<NewsInfo>();
            newsinfo = NewsInfoLogic.GetPageNewsInfo(PAGESIZE, nowPage);
            foreach (var ni in newsinfo)
            {
                NewsInfoList nl = (NewsInfoList)ni;
                nl.CategoryName = NewsCategoryInfoLogic.GetOneNewsCategoryInfo(ni.CategoryID).CategoryName;
                newslist.Add(nl);
            }
            NewsListRpt.DataSource = newslist;
            NewsListRpt.DataBind();
        }
        private void NewsListPageBindData(int nowPage)
        {
            List<int> page = new List<int>();
            for(int i=1;i<=pagecount;i++){
                if (i != nowPage)
                    page.Add(i);
            }
            NewsListPage.DataSource = page;
            NewsListPage.DataBind();
        }
    }
}
